home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
preccx
/
prccx240.lha
/
ccdata.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-04-18
|
3KB
|
113 lines
/*
* parser suite - and / or / nothing / something parsers
*
* parser = [token] -> ([token],status)
*
* implemented as sideeffecting on [token], returns status.
*/
#include "cc.h"
#include <stdlib.h>
#ifdef __MSDOS__
#include <alloc.h>
#define INDOS 1
#else
#define INDOS 0
#endif
VOID p_creat_data ()
/* we think one of the stacks at least is NULL, and we try and alloc it */
{
long bytesfree;
bytesfree = p_memleft ();
/* but which stack is it? */
/* compilation warnings for maybe losing digits from the args of
* p_calloc should always be ignored. The numbers can't be that big! */
if (buffer == NULL)
buffer = (TOKEN *) p_calloc (precc_data.readbuffersize, sizeof (TOKEN));
if (lvbuff == NULL)
lvbuff = (VALUE *) p_calloc (precc_data.readbuffersize, sizeof (VALUE));
if (program == NULL)
program = (INSTRUCTION *) p_calloc (precc_data.maxprogramsize,
sizeof (INSTRUCTION));
if (stack == NULL) {
stack = (STACKVALUE *) p_calloc (precc_data.stacksize, sizeof (STACKVALUE));
value = stack; /* top of evaluation stack */
}
if (fstack == NULL) {
fstack = (FRAME *) p_calloc (precc_data.contextstacksize, sizeof (FRAME));
fptr = fstack;
}
if (buffer == NULL || lvbuff == NULL || program == NULL || stack == NULL || fstack == NULL) {
fprintf (stderr,
"error; not enough memory (%lu) for internal stacks\n", bytesfree);
exit (1);
}
return;
}
VOID p_destr_data ()
{
if (buffer != NULL)
p_free (buffer);
if (lvbuff != NULL)
p_free (lvbuff);
if (program != NULL)
p_free (program);
if (stack != NULL)
p_free (stack);
if (fstack != NULL)
p_free (fstack);
return;
}
/* globals */
int p_argc;
char **p_argv;
TOKEN *buffer; /* where the pstr points to */
TOKEN *yybuffer; /* internal name for buffer */
VALUE *lvbuff; /* the parallel stack of yylvals */
INSTRUCTION *program;
STACKVALUE *stack; /* the evaluation stack - either values or
* tokens */
STACKVALUE *value;
FRAME p_frame; /* all one needs to know for a rewind */
FRAME *fstack;
FRAME *fptr;
/* this IS a frame */
TOKEN *pstr; /* parsed stream */
int pc; /* program counter - counts up from 0 */
int passcount; /* input lines counted here */
/* end of frame */
INSTRUCTION instr; /* instruction cache */
TOKEN *maxp; /* maximum number parsed so far */
int call_mode = 0; /* flag for call convention. 1 = pascal
* (manual), 0 = C (auto) */
jmp_buf jmpb; /* environment */
int optimize = 0; /* flag for flying program optimization */
int msdos = INDOS; /* 1 if we're in MSDOS */
PARSER *p_entry; /* entry point set by p_run & btck_error */
int p_enargs;
PARAM p_eargv[MAXARGS];
PRECC_DATA precc_data;